package com.beiming.libra.config;

import java.util.List;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import com.beiming.libra.helper.CustomFormHttpMessageConverter;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

  @Override
  public void addViewControllers(ViewControllerRegistry registry) {
    registry.addViewController("/testVideo").setViewName("/testVideo");
    registry.addViewController("/testOnlineVideo").setViewName("/testOnlineVideo");
    registry.addViewController("/testPusher").setViewName("/testPusher");
    registry.addViewController("/login").setViewName("/login");
    registry.addViewController("/chatRoom").setViewName("/chatRoom");
    registry.addViewController("/testWebSocket").setViewName("/testWebSocket");
  }

  @Override
  public void addCorsMappings(CorsRegistry registry) {
    registry.addMapping("/**").allowedOrigins("*").allowedHeaders("*").allowedMethods("*");
  }

  @Override
  public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
    converters.add(new CustomFormHttpMessageConverter());
  }
}
